# -*- coding: utf-8 -*-

from inspect import Signature, Parameter
from typing import Iterable

# from contract_market.error.error import ArgumentTypeError
# TypeError: abc() missing 1 required positional argument: 'a'


def make_argument(fields: Iterable):
    """ """
    params = [Parameter(name, Parameter.POSITIONAL_OR_KEYWORD)
              for name in fields]
    return Signature(params)


class Structure(type):
    """ """

    def __init__(cls, basename, baseargs, basekw):
        """ """

        fields = basekw.get("_fields", [])
        cls.__annotations__ = make_argument(fields)
        return super().__init__(basename, baseargs, basekw)


class InitStructure(metaclass=Structure):
    """ """
    _fields = []

    def __init__(self, *args, **kwargs) -> None:
        """ """

        bound_values = self.__annotations__.bind(*args, **kwargs)
        for name, value in bound_values.arguments.items():
            setattr(self, name, value)
